package com.itheima.mall.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.itheima.mall.mapper.SkuStockMapper;
import com.itheima.mall.pojo.SkuStock;
import com.itheima.mall.service.PmsSkuStockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PmsSkuStockServiceImpl extends ServiceImpl <SkuStockMapper , SkuStock>implements PmsSkuStockService {

  @Autowired
  private SkuStockMapper skuStockMapper;
    //根据id更新
    @Override
    public void updateSkuStocksByPid(Integer pid, List<SkuStock>  skuStockList) {
       skuStockMapper.updateSkuStocksByPid(pid , skuStockList);

    }
    //根据商品ID及sku编码模糊搜索sku库存
    @Override
    public List<SkuStock>  selectSkuStockById(Integer pid, String keyword) {
        LambdaQueryWrapper<SkuStock> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.like(keyword != null , SkuStock::getSkuCode , keyword);
        lambdaQueryWrapper.eq(SkuStock::getProductId , pid);
        List<SkuStock> list = skuStockMapper.selectList(lambdaQueryWrapper);
        return list;
    }
}
